package fr.cnam.projetSiw.client.structure.pages.suggest;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

import fr.cnam.projetSiw.client.core.ClientFactory;
import fr.cnam.projetSiw.client.core.ZicActivity;
import fr.cnam.projetSiw.client.services.SparqlService;
import fr.cnam.projetSiw.client.services.SparqlServiceAsync;

public class SuggestGenreActivity extends ZicActivity implements SuggestGenreView.Presenter{

	
	private SparqlServiceAsync sparqlService = GWT.create(SparqlService.class);

	public SuggestGenreActivity(ClientFactory clientFactory) {
		super(clientFactory);
	}

	@Override
	public void start(AcceptsOneWidget panel, final EventBus eventBus) {
		final SuggestGenreView view = clientFactory.getSuggestGenreView();
		view.setPresenter(this);
		panel.setWidget(view);
		
		
		view.setGenreChangedCommand(new Command() {
			
			@Override
			public void execute() {
				eventBus.fireEvent(new GenreChangedEvent(view.getGenre()));
			}
		});
		
		sparqlService.getAllGenre(new AsyncCallback<ArrayList<String>>() {
			
			@Override
			public void onSuccess(ArrayList<String> result) {
				view.setAllGenre(result);
			}
			
			@Override
			public void onFailure(Throwable caught) {
				
			}
		});
	}

}
